﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Drawing;
using System.Drawing.Text;
using System.Drawing.Imaging;
using System.ServiceModel;
using ListenMusic.Models.User;
using ListenMusic.User_ServiceReference;
using ListenMusic.Controllers.Public;
namespace ListenMusic.Controllers.User
{
    public class UserController : HomeController
    {
        //
        // GET: /User/      
        private UserRepository ur;
        public UserController()
        {
            ur = new UserRepository();
        }
        public ActionResult Register()
        {            
            return View();            
        }
        public void create_Capcha()
        {
            Bitmap objBMP = new Bitmap(60,20);
            Graphics objGraphics = Graphics.FromImage(objBMP);
            objGraphics.Clear(Color.Bisque);
            objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
            Font objFont = new Font("Tahoma", 12, FontStyle.Bold);
            string randomStr = "";
            int[] myIntArray = new int[5];
            int x;
            Random autoRand = new Random();
            for (x = 0; x < 5; x++)
            {
                myIntArray[x] = Convert.ToInt32(autoRand.Next(0, 9));
                randomStr += (myIntArray[x].ToString());
            }
            Session.Add("capcha", randomStr);
            objGraphics.DrawString(randomStr, objFont, Brushes.White, 3, 3);
            //objBMP.Save(Response.OutputStream, ImageFormat.Gif);
            objBMP.Save(Server.MapPath("~/Images/Capcha/") + randomStr + ".gif", ImageFormat.Gif); 
            //Response.ContentType = "image/GIF";
            objFont.Dispose();
            objGraphics.Dispose();
            objBMP.Dispose();
        }
        public ActionResult Login(string email,string password)
        {
            try
            {
                Member m = ur.checkLogin(email, password);
                return View("~/Views/Shared/_LayoutPublic.cshtml");
            }
            catch (FaultException ex)
            {
                throw ex;
            }
        }
    }
    
}
